Ask a Question
Send an email to me.
 
Java Question and Answer Forums
JavaRanch Big Moose Saloon
Marcus Green's Discussion Forum
java.sun.com Forums, Chat and User Groups
Artima Java Answers Forum
 
Other Resources
Java Language Specification
Java Virtual Machine Specification
Java 2 Platform, Standard Edition, v 1.4.0 API Specification
 
Tutorials
Learning the Java Language
Operator Precedence Chart, Expressions, Statements, Blocks
Programming with Assertions
 
Answers: Certified Java Programmer Mock Exam
No.AnswerRemark
1c  d  Compiler error at line 3.  Compiler error at line 4.  Methods declared in an interface are implicitly public. A compiler error is generated if an attempt is made to declare a method with a weaker access privilige. If no access modifier is included in the method declaration then the method is implicitly public.  
2 All field declarations within an interface are implicitly public, static and final. Use of these modifiers is redundant but legal. No other modifiers can be applied to a field declaration within an interface.  
3a  g  abstract  public  All interfaces are implicitly abstract. The application of the abstract modifier to an interface is discouraged. The private, protected, and static modifiers are applicable to member interfaces only. An interface can not be final. The keywords "extends" and "implements" are not modifiers.  
4c  d  e  Compiler error at line 3.  Compiler error at line 4.  Compiler error at line 5.  A method declared in an interface is implicitly public. Any class that implements the interface must not assign weaker access privileges.  
5b  c  The relationship between a class and its super class is an example of an "is-a" relationship.  The relationship between a class and a field within the class is an example of a "has-a" relationship.  Inheritance is an example of an "is-a" relationship because the sub class "is-a" specialized type of the super class. The relationship between a class and a field within the class is an example of a "has-a" relationship because the class "has-a" instance of the declared field.  
6b  c  d  2  3  4  All methods declared within an interface are implicitly abstract. The final, synchronized, native, and strictfp modifiers can not appear in the declaration of an abstract method and can not be applied to an abstract method declared in an interface.  
7a  b  c  d  An interface that is declared within the body of a class or interface is known as a nested interface.  A constant can be a member of an interface.  An abstract method declaration can be a member of an interface.  A class declaration can be a member of an interface.  An interface can be declared within an enclosing class or interface. The members of an interface can be constants, abstract method declarations, class declarations, or interface declarations.  
8a  d  e  f  g  public  abstract  static  final  strictfp  A class that is declared within an enclosing interface is implicitly public and static so the access modifiers protected and private are not permitted.  
9a  e  static  strictfp  The private, protected, and static modifiers are applicable to member interfaces only. The synchronized modifier is applicable only to concrete implementations of methods. The volatile and transient modifiers are only applicable to variables that are members of a class. The strictfp modifier causes all float and double expressions within the interface declaration to be FP-strict. Please note that the abstract methods declared within the interface are never strictfp.  
10h  None of the Above  Overloaded methods may have different return types and a different throws clause.  
11a  e  f  g  abstract  private  protected  public  All interfaces are implicitly abstract. The explicit application of the abstract modifier to an interface is redundant and discouraged. The private, protected, and static modifiers are applicable to member interfaces only. The "final" modifier is never applicable to an interface. The "extends" and "implements" keywords are not modifiers.  
12a  An interface declaration can be a member of an interface.  An interface can be declared within an enclosing class or interface. The members of an interface can be constants, abstract method declarations, class declarations, or interface declarations. The body of a method declared within an interface is represented by a semicolon. An interface can extend another interface but can not implement an interface. An abstract class that implements an interface need not provide implementations for any of the methods declared within the interface.  
13b  Prints: R.printS1 S.printS2  Method R.printS1 is private and therefore is not inherited by class S and is not overridden by method S.printS1. In contrast, method R.printS2 is protected and therefore is inherited by class S and is overridden by method S.printS2. R.printS1S2 therefore calls the R.printS1 and S.printS2 methods.  
14b  Prints: B.s1 A.s2 A.s1 A.s2  The variables of a subclass can hide the variables of a superclass or interface. The variable that is accessed depends on the type of the reference.  
15 All methods declared within an interface are implicitly abstract and public. Although the abstract and public modifiers can legally be applied to a method declaration in an interface the usage is redundant and is discouraged. Since all methods declared within an interface are implicitly public a weaker access level can not be declared for an implementing method. An abstract class that implements an interface is free to override one of the interface methods with another abstract method declaration.  
16f  System.out.print(new C().new D().m1());  A class nested within an enclosing interface can legally implement the enclosing interface. Class C implements interface A and inherits all of the declarations within A including the declaration of the nested class B. Class D extends the nested class B. Class D is not static and therefore can not be instantiated without being associated with an instance of the enclosing class C. The following expression first creates an instance of the enclosing class C and then creates an instance of the inner class D: new C().new D().  
17b  Prints: B,SuperB,A,SuperA  The expression A.this.s1 is an example of a "qualified this" expression. The expression A.super.s1 is the same as ((SuperA)A.this).s1.  

Copyright © 2002, Dan Chisholm
All rights reserved.
1